package com.woniu.p2p.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.p2p.entity.Coupon;
import com.woniu.p2p.entity.User;
import com.woniu.p2p.entity.UserCoupon;
import com.woniu.p2p.mapper.CouponMapper;
import com.woniu.p2p.mapper.UserMapper;
import com.woniu.p2p.service.P2PCouponService;
import com.woniu.p2p.vo.CouponAndUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86152
 * @create 2020/8/11
 * @since 1.0.0
 */
@Service
public class P2PCouponServiceImp implements P2PCouponService {
    @Autowired
    CouponMapper couponMapper;

    /*根据当前页码获取分页数据*/
    @Override
    public PageInfo<UserCoupon> findallcoupon(int i, int i1, int userid) {
        PageHelper.startPage(i,i1);
        List<UserCoupon> userCoupons= couponMapper.findByid(userid);
        PageInfo<UserCoupon> userCouponPageInfo = new PageInfo<>(userCoupons);
        return userCouponPageInfo;
    }
    @Autowired
    UserMapper userMapper;
    /*查询用户和优惠券信息*/
    @Override
    public CouponAndUserVo findcouponanduserbyid(int userid, Integer couponId) {
        User user = userMapper.selectByPrimaryKey(userid);
        Coupon coupon = couponMapper.selectByPrimaryKey(couponId);
        CouponAndUserVo couponAndUserVo = new CouponAndUserVo();
        couponAndUserVo.setUser(user);
        couponAndUserVo.setCoupon(coupon);
        return couponAndUserVo;
    }
}
